Imports Clo = Enhancements.Core.Logging
Imports Fun = Enhancements.Basic.Expressions.Functions
Imports Ref = System.Reflection
Imports Sys = System

Namespace Enhancements.Basic.Expressions
    ''' <summary>The exception that is thrown when a function call solving threw an exception.</summary>
    ''' <remarks>The InnerException property holds the exception that leads to the throwing of these exceptions.</remarks>
    <Serializable(), DebuggerStepThrough()> _
    Public NotInheritable Class ExpressionFunctionCallSolvingException
        Inherits Exception

        Private Sub New(ByVal _expression As Expression, ByVal _functionCall As Fun.FunctionCall, ByVal _parameters() As Sys.Object, ByVal _innerException As Sys.Exception)
            MyBase.New(_innerException)
            Expression = _expression
            FunctionCall = _functionCall
            Parameters = _parameters
        End Sub

        Private __Expression As Expression = Nothing
        ''' <summary>Gets the expression that caused this exception.</summary>
        Public Property Expression() As Expression
            Get
                Return __Expression
            End Get
            Private Set(ByVal _value As Expression)
                __Expression = _value
            End Set
        End Property

        Private __FunctionCall As Fun.FunctionCall = Nothing
        ''' <summary>Gets the function call that caused this exception.</summary>
        Public Property FunctionCall() As Fun.FunctionCall
            Get
                Return __FunctionCall
            End Get
            Private Set(ByVal _value As Fun.FunctionCall)
                __FunctionCall = _value
            End Set
        End Property

        Private __Parameters() As Sys.Object = {}
        ''' <summary>Gets the parameters sent to the function call that caused this exception.</summary>
        Public Property Parameters() As Sys.Object()
            Get
                Return __Parameters
            End Get
            Private Set(ByVal _value() As Sys.Object)
                __Parameters = _value
            End Set
        End Property

        ''' <summary>Throws an exception.</summary>
        ''' <param name="_expression">Expression that is causing the exception.</param>
        ''' <param name="_functionCall">Function call that is causing the exception.</param>
        ''' <param name="_parameters">Parameters sent to the function call that is causing the exception.</param>
        ''' <exception cref="ExpressionFunctionCallSolvingException"> </exception>
        Friend Shared Sub ___Throw(ByVal _expression As Expression, ByVal _functionCall As Fun.FunctionCall, ByVal _parameters() As Sys.Object, ByVal _innerException As Sys.Exception)
            Dim _exception As ExpressionFunctionCallSolvingException = New ExpressionFunctionCallSolvingException(_expression, _functionCall, _parameters, _innerException)

            Throw _exception
        End Sub

    End Class
End Namespace
